<?php
$this->lang->load('template');
$this->load->view('admin/common/header',array('_user'=>$_user,'modules'=>$modules,'pageTitle'=>'推荐广告管理'));
 $advs = array(
  'attr' => array(
	  'class' => 'index'
  ),
 'fields' => array(
		'id' => array('label'=>$this->lang->line('tpl_id'),'is_sort'=>false ),
		'ad_name' => array('label'=>$this->lang->line('tpl_name'),'is_sort'=>false,'filter'=>'__doFilter'),  
		'media_type' => array('label'=>$this->lang->line('tpl_type'),'is_sort'=>false,'filter'=>'__doFilter'),  
		//'start_at' => array('label'=>__('开始日期'),'is_sort'=>false,'filter'=>'__doFilter'),
		//'end_at'  => array('label'=>__('结束日期'),'is_sort'=>false,'filter'=>'__doFilter'),
  		'action' => array('label' => $this->lang->line('tpl_actions'),'filter'=>'__doFilter' ),
	),
  'data' => isset($result['result']) ? $result['result'] : null,
);
function __doFilter($f,$r){
	$str = isset($r[$f])?$r[$f]:'';
	if($f=='media_type')
	{
		$mediaType = array('text'=>'文本', 'image'=>'图片', 'flash'=>'flash');
		$str = $mediaType[$str];
	}elseif($f=='action'){
		$str = '<a href="%s" class="edit_link" title="编辑"><img alt="Edit" src="'.base_url('images/admin/icons/edit.png').'" /></a>';
		$str .= '&nbsp;';
		$str .= '<a href="%s" class="remove_image_link" rel="'.$r['id'].'" title="删除"><img alt="Edit" src="'.base_url('images/admin/icons/delete.png').'" /> 删除</a>';
		$str = sprintf($str,site_url('admin/ads/edit/'.$r['id']), site_url('admin/ads/remove/'.$r['id']));
	}elseif($f=='start_at'||$f=='end_at'){
		$str = date('Y-m-d',$r[$f]);
	}
	$str = empty($str) ? '&nbsp;&nbsp;':$str;
	return $str;
}
?>
<style>
.tr span {
	clear:both;
	display:block;
	color:#999
}
</style>
<script language="javascript">
$(document).ready(function(){
	$('.remove_image_link').click(
		function(event){
			event.preventDefault();
			url = this.href+'&format=json';
			return Admin.remove(
				url,
				'您确定删除该数据吗？'
			);
		}
	);
});
</script>
<div class="clear tile_bg" id="content">
  <div class='toolbar'>
    <ul class='actions'>
      <li> <a href="<?=site_url('admin/ads/create')?>" class="button" id="new_item_link"><span><img alt="Add" src="<?=base_url('images/admin/icons/add.png')?>" />添加</span></a> </li>
    </ul>
    <br class='clear' />
  </div>
  <h1>广告列表 </h1>
  <div id="new-item"></div>
  <?=htmlTable($advs);?>
  <?php 
  	if (isset($result['pager'])) :
  ?>
  <div id="pagination" class="pagination"> 
  	<?php
  		echo $result['pager']->create_links();
  	?>
  </div>
  <?php endif;?>
  <br class='clear' />
</div>
</div>
<?php $this->load->view('admin/common/footer');?>